/*
 * acm2478.c
 *
 *  Created on: 5 Apr 2010
 *      Author: xuxu
 */

#include<stdio.h>
#include<string.h>
int main()
{
	char word[110];
	int len;
	int n;
	int i,con;
	char ch;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%s",word);
		len=strlen(word);
		for(i=0;i<len;i++)
		{
			ch=word[i];
			con=1;
			while(i+1<len&&word[i]==word[i+1])
			{
				con++;
				i++;
			}
			if(con>1)
				printf("%d",con);
			printf("%c",ch);
		}
		printf("\n");
	}
	return 0;
}
